//
//  SoapRequest.m
//  AF
//
//  Created by Avon Xu on 16/1/13.
//  Copyright © 2016年 Avon Xu. All rights reserved.
//

#import "SoapRequest.h"
#import "RequestManager.h"

@implementation SoapRequest


+(NSString*)defaultSoapMesage {
    NSString *soapBody =@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
    "<soap:Body>%@</soap:Body></soap:Envelope>";
    return soapBody;
}

+(NSString*)methodSoapMessage:(NSString*)methodName {
    NSMutableString *soap =[NSMutableString stringWithFormat:@"<%@ xmlns=\"%@\">",methodName,WebServiceNameSpace];
    [soap appendString:@"%@"];
    [soap appendFormat:@"</%@>",methodName];
    return [NSString stringWithFormat:[self defaultSoapMesage],soap];
}


+(NSString *)dictionaryToDefaultSoapMessage:(NSDictionary*)dic methodName:(NSString*)methodName {
    if ([dic count] == 0 ||dic == nil) {
       return [NSString stringWithFormat:[self methodSoapMessage:methodName],@""];
    }
    
    NSMutableString *msg =[NSMutableString stringWithFormat:@""];
    
    NSArray *keysCount = [dic allKeys];
    
    for (NSInteger i = 0; i<[keysCount count]; i++) {
        NSString *key = [keysCount objectAtIndex:i];
        [msg appendFormat:@"<%@>",key];
        [msg appendString:[dic objectForKey:key]];
        [msg appendFormat:@"</%@>",key];
    }
    return [NSString stringWithFormat:[self methodSoapMessage:methodName],msg];
}

@end
